home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-05 | 2.1 KB | 99 lines | [MATS/MATL] |
- echo off;
- % NUMERICAL METHODS: MATLAB Programs, (c) John H. Mathews 1994
- % To accompany the text:
- % NUMERICAL METHODS for Mathematics, Science and Engineering, 2nd Ed, 1992
- % Prentice Hall, Englewood Cliffs, New Jersey, 07632, U.S.A.
- % This free software is complements of the author.
-
- % Algorithm 10.4 (Dirichlet Method for Laplace's Equation).
- % Section 10.3, Elliptic Equations, Page 531
- echo on; clc; format short; hold off; clear
-
- % ELLIPTIC EQUATIONS.
-
- % Dirichlet solution for the heat equation
-
- % u (x,y) + u (x,y) = 0
- % xx yy
-
- % with the boundary values:'
-
- % u(x,0) = f1(x), u(x,b) = f2(x) for 0 ≤ x ≤ a,
-
- % u(0,y) = f3(y), u(a,y) = f4(y) for 0 ≤ y ≤ b,
-
- % A numerical approximation is computed over the rectangle
-
- % 0 ≤ x ≤ a , 0 ≤ y ≤ b.
-
- pause % Press any key to continue.
-
- clc;
- % Store f1(x),f2(x),f3(y),f4(y) in f1.m f2.m f3.m f4.m
-
- % function z = f1(x)
- % z = 20;
-
- % function z = f2(x)
- % z = 180;
-
- % function z = f3(y)
- % z = 80;
-
- % function z = f4(y)
- % z = 0;
-
- delete f1.m
- diary f1.m; disp('function z = f1(x)');...
- disp('z = 20;');...
- diary off;
-
- delete f2.m
- diary f2.m; disp('function z = f2(x)');...
- disp('z = 180;');...
- diary off;
-
- delete f3.m
- diary f3.m; disp('function z = f3(y)');...
- disp('z = 80;');...
- diary off;
-
- delete f4.m
- diary f4.m; disp('function z = f4(y)');...
- disp('z = 0;');...
- diary off;
-
- % Remark. f1.m f2.m f3.m f4.m dirich.m are used for Algorithm 10.4
- f1(0); f2(0); f3(0); f4(0);
- pause % Press any key to continue.
-
- clc;
- % Place the endpoint of [0,a] in a.
- % Place the endpoint of [0,b] in b.
- % Place the step size in h.
- % Place the tolerance in tol.
- % Place the maximum number of iterations in max1.
-
- a = 4.0;
- b = 4.0;
- h = 0.5;
- tol = 0.001;
- max1 = 25;
-
- % Proceeding with the iteration.
-
- U = dirich('f1','f2','f3','f4',a,b,h,tol,max1);
-
- pause % Press any key to see the solution.
-
- clc; clg;
- mesh(U);...
- Mx1 = 'The solution to Laplace`s equation.';...
- title(Mx1);...
- shg; pause % Press any key to continue.
-
- W = rot90(U);
- clc,echo off,diary output,...
- disp(' '),disp(Mx1),disp(' '),disp(W),...
- diary off,echo on
-